package com.gict.antifraudback.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 常用校验正则表达式
 */
public class Validator {

    public static boolean isValidEmail(String email) {
        // 定义邮箱格式的正则表达式
        String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";

        // 创建 Pattern 对象
        Pattern pattern = Pattern.compile(emailRegex);

        // 创建 matcher 对象
        Matcher matcher = pattern.matcher(email);

        // 校验邮箱格式是否匹配
        return matcher.matches();
    }

    public static void main(String[] args) {
        // 测试邮箱格式
        String email1 = "test@example.com";
        String email2 = "invalid-email";
        
        System.out.println(email1 + " is valid: " + isValidEmail(email1));
        System.out.println(email2 + " is valid: " + isValidEmail(email2));
    }
}
